import App from './App'
import p from './utils/public';
import "./common/config/public";
import Http from './common/service/export.js';
import config from "./common/config/index.js";
import utils from "./common/utils/index.js";


import uView from "uview-ui";
Vue.use(uView);

Vue.prototype.$p = p;
Vue.prototype.$http = Http;
Vue.prototype.$msg = function(tit = '', data = 'none') {
	uni.showToast({
		icon: data,
		title: tit
	})
}
const getUserInfo = {
	getUserInfo(cb) {
		uni.request({
			url: utils.checkUrl() +  '/home/user/getUserInfo', //仅为示例，并非真实接口地址。
			data: {},
			header: {
				"Content-Type": "application/json;charset=utf-8",
				'x-requested-with': 'XMLHttpRequest',
				"cmx-token": uni.getStorageSync('token') ? uni.getStorageSync('token') : '',
				"cmx-id": uni.getStorageSync('id') ? uni.getStorageSync('id') : '',
			},
			success: (res) => {
				//  console.log(res.data.data);
				if (res.data.code == 1) {
					uni.setStorageSync("userinfo", res.data.data);
					uni.setStorageSync("user_money", res.data.data.user_money);
				} else if (res.data.code == 10000) {
					uni.showToast({
						title: '暂未登陆！请登录',
						duration: 1000,
						icon: 'none'
					});
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/login/login'
						})
					}, 1000);
				}
				cb && cb(res.data);
			}
		});
	}
}

Vue.prototype.$getUserInfo = getUserInfo


// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif